package com.ctsi.ssdc.service.impl;

import com.ctsi.ssdc.entity.Excel09;
import com.ctsi.ssdc.entity.IndustrialEconomicIndicators;
import com.ctsi.ssdc.mapper.Excel09Mapper;
import com.ctsi.ssdc.service.Excel09Service;
import com.ctsi.ssdc.utils.TimeUtil;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Future;

/**
 * 9基础表工业分行业(效益)(Excel09)表服务实现类
 *
 * @author makejava
 * @since 2023-02-20 13:05:52
 */
@Service("excel09Service")
public class Excel09ServiceImpl implements Excel09Service {
    @Resource
    private Excel09Mapper excel09Mapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Excel09 queryById(Long id) {
        return this.excel09Mapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param excel09     筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<Excel09> queryByPage(Excel09 excel09, PageRequest pageRequest) {
        long total = this.excel09Mapper.count(excel09);
        return new PageImpl<>(this.excel09Mapper.queryAllByLimit(excel09, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param excel09 实例对象
     * @return 实例对象
     */
    @Override
    public Excel09 insert(Excel09 excel09) {
        this.excel09Mapper.insert(excel09);
        return excel09;
    }

    /**
     * 修改数据
     *
     * @param excel09 实例对象
     * @return 实例对象
     */
    @Override
    public Excel09 update(Excel09 excel09) {
        this.excel09Mapper.update(excel09);
        return this.queryById(excel09.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.excel09Mapper.deleteById(id) > 0;
    }

     /**
     *  批量添加数据
     * @param list
     * @return 是否成功
     */
    @Override
    public boolean insertBatch(List<Excel09> list) {
        return this.excel09Mapper.insertBatch(list) > 0;
    }


    /**
     * 根据日期删除
     * @param date
     * @return 是否成功
     */
    @Override
    public boolean removeByDate(Date date) {
        return excel09Mapper.removeByDate(date);
    }


    @Override
    public IndustrialEconomicIndicators getTotalProfit(String year, String month) {
        IndustrialEconomicIndicators info = excel09Mapper.getTotalProfit(year, month);
        if (info != null) {
            info.setStatisticalTime(TimeUtil.date(year, month));
            info.setIndicators("利润总额");
        }
        return info;
    }

    @Override
    public IndustrialEconomicIndicators getTotalTaxes(String year, String month) {
        IndustrialEconomicIndicators info = excel09Mapper.getTotalTaxes(year, month);
        if (info != null) {
            info.setStatisticalTime(TimeUtil.date(year, month));
            info.setIndicators("利税总额");
        }
        return info;
    }
}
